package com.shenmazong.serverwebpoem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.shenmazong.serverwebpoem.mapper.ITbAppreciationMapper;
import com.shenmazong.serverwebpoem.pojo.TbAppreciation;
import com.shenmazong.serverwebpoem.service.TbAppreciationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author 田不平
 * @project server-web-poem
 * @date 2020/3/23 7:49 PM
 * http://www.shenmazong.com
 */

@Slf4j
@Service
public class TbAppreciationServiceImpl implements TbAppreciationService {

    @Autowired
    ITbAppreciationMapper iTbAppreciationMapper;

    @Override
    public void add(TbAppreciation appreciation) {
        iTbAppreciationMapper.insert(appreciation);
    }

    @Override
    public void del(Integer id) {
        iTbAppreciationMapper.deleteById(id);
    }

    @Override
    public void set(TbAppreciation appreciation) {
        iTbAppreciationMapper.updateById(appreciation);
    }

    @Override
    public TbAppreciation getById(Integer id) {
        return iTbAppreciationMapper.selectById(id);
    }

    @Override
    public List<TbAppreciation> getByPoetryId(Integer id) {

        Map<String,Object> columnMap = new HashMap<>();
        columnMap.put("poetryid", id);
        List<TbAppreciation> appreciations = iTbAppreciationMapper.selectByMap(columnMap);

        return appreciations;
    }

    @Override
    public IPage<TbAppreciation> getNoteByPage(Integer pageCurrent, Integer pageSize) {
        QueryWrapper<TbAppreciation> queryWrapper = new QueryWrapper<>();
        //queryWrapper.eq("authorid", authorId);
        queryWrapper.orderByAsc("verify");
        queryWrapper.orderByDesc("id");

        Page<TbAppreciation> page = new Page<>(pageCurrent, pageSize);
        IPage<TbAppreciation> iPage = iTbAppreciationMapper.selectPage(page, queryWrapper);
        System.out.println("总页数:"+iPage.getPages());
        System.out.println("总记录数:"+iPage.getTotal());

        return iPage;
    }
}
